import {
  Controller,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { UploadService } from './upload.service';
import { FileInterceptor } from '@nestjs/platform-express';

@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  @Post()
  @UseInterceptors(FileInterceptor('file'))
  image(@UploadedFile() file: Express.Multer.File) {
    return {
      code: 200,
      message: '上传成功',
    };
  }
  @Post('/video')
  @UseInterceptors(FileInterceptor('file'))
  async video(@UploadedFile() file: Express.Multer.File) {
    const videoPath = file.path; // 上传的视频文件的路径
    // 调用 VideoService 中的方法来截取封面
    const data = await this.uploadService.processVideoAndExtractThumbnail(
      videoPath,
    );

    return {
      code: 200,
      message: '上传成功',
      data,
    };
  }
}
